package com.china.api.wechat.processor.main;

import java.lang.reflect.Method;

/**
 * @Description:
 * @author:larry
 * @version:v1.0.0
 * @Created:2013-10-17上午11:26:15
 * @Modified:
 */
public class Action {
	private Processor processor;
	private Method method;
	private String replyMappingId;
	
	public Action(Processor processor, Method method) {
		this.processor = processor;
		this.method = method;
	}
	
	public Action(Processor processor, Method method, String replyMappingId) {
		this.processor = processor;
		this.method = method;
		this.replyMappingId = replyMappingId;
	}

	public Response execute(String content, Session session) throws Exception{
		HistoryFrame currentFrame = new HistoryFrame();
		if(replyMappingId != null && !"".equals(replyMappingId)){
			currentFrame.setReplyMappingId(replyMappingId);
		}
		session.getHistory().push(currentFrame);
		Response ret = (Response) method.invoke(processor, content, session);
		return ret;
	}
}
